package org.dromara.comm_lhz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.comm_lhz.entity.AsActivityAnswerEntity;
import org.dromara.comm_lhz.entity.dto.AsAnswerDto;
import org.dromara.comm_lhz.entity.vo.AsActivityAnswerVo;
import org.dromara.comm_lhz.service.AsActivityAnswerHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.domain.Pageable;

/**
 * 活动问答控制器
 * 负责处理与活动问答相关的HTTP请求
 */
@RestController
@RequestMapping("/answer")
public class AsActivityAnswerHController {

    // 服务层对象，用于处理具体的业务逻辑
    @Autowired
    private AsActivityAnswerHService asActivityAnswerHService;

    /**
     * 获取问答信息
     *
     * @param asActivityAnswerEntity 封装了查询条件的实体对象
     * @param pageable 分页信息
     * @return 分页的问答信息列表
     */
    @GetMapping("/getAnswer")
    public Page<AsActivityAnswerVo> getAnswer(AsActivityAnswerEntity asActivityAnswerEntity, Pageable pageable){
        return asActivityAnswerHService.getAnswer(asActivityAnswerEntity, pageable);
    }

    /**
     * 添加问答信息
     *
     * @param asAnswerDto 封装了问答信息的DTO对象
     */
    @PostMapping("/addAnswer")
    public void addAnswer(@RequestBody AsAnswerDto asAnswerDto){
        asActivityAnswerHService.addAnswer(asAnswerDto);
    }

    /**
     * 修改问答信息
     *
     * @param asAnswerDto 封装了问答信息的DTO对象
     */
    @PostMapping("/updateAnswer")
    public void updateAnswer(@RequestBody AsAnswerDto asAnswerDto){
        asActivityAnswerHService.updateAnswer(asAnswerDto);
    }

    /**
     * 删除问答信息
     *
     * @param asAnswerDto 封装了问答ID的DTO对象
     */
    @PostMapping("/deleteAnswer")
    public void deleteAnswer(@RequestBody AsAnswerDto asAnswerDto){
        asActivityAnswerHService.removeById(asAnswerDto.getId());
    }

}
